package com.example.springboot.modules.system.controller;


import com.example.springboot.common.utils.JsonResult;
import com.example.springboot.modules.system.model.SysUser;
import com.example.springboot.modules.system.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping
public class LoginController {
    @Autowired
    private LoginService loginService;

    @RequestMapping(value="/toLogin" ,method = RequestMethod.POST)
    @ResponseBody
    public JsonResult<SysUser> toLogin(SysUser sysUser){
        SysUser user=null;
        try {
            user=loginService.toLogin(sysUser);
            if(user==null){
                return new JsonResult<>(1,"用户名或密码错误");
            }
        }catch (Exception e){
            return new JsonResult<>(e);
        }
        return new JsonResult<>(user);
    }
}